﻿
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Hosting;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using YunShop_WebAPI.BLL;
using YunShop_WebAPI.Model;

namespace YunShop_WebAPI.API
{
    public partial class index : System.Web.UI.Page
    {
        string shop_appid = "uNZj+qel5cinjdXtIWvtmQ==";
        protected async void Page_Load(object sender, EventArgs e)
        {

            string mjson = "{'aesKeyVersion':1,'message':{'group_status':'-1','is_wtt_order':'null','express_fee':'0.00','argue_flag':0,'is_wei_order':'0','express':'','express_no':'','total':'0.02','seller_name':'wpJ/Q8jPVPwOoRVtnLFXsYLy3ys9ND8Bt188h3LsxTc=','status_ori':'50','is_over_sold':'0','supplier_seller_id':0,'price':'0.02','refund_status_ori':'0','original_total_price':'0.02','last_income':'0.02','order_type':'3','seller_id':'1780485109','quantity':'1','confirm_expire':'','status_desc':'已完成','buyer_info':{'name':'4YqSn8aCeN1dWqmQUjbWK+y7nVVnMh7XdqTmn9QGsXw='},'f_seller_id':'0','is_close':0,'is_cpn_order':'0','finish_time':'2024-12-27 14:48:19','pay_time':'2024-12-27 14:48:19','express_fee_num':'0.00','express_note':'','order_type_desc':'交易资金担保服务','add_time':'2024-12-27 14:48:15','items':[{'sku_merchant_code':'','img':'https://si.geilicdn.com/ch1553385727-066e00000189d9c63d030a23029f_4032_3024.jpg?w=110&h=110&cp=1','merchant_code':'','quantity':'1','total_price':'0.02','item_id':'7336737643','is_delivered':0,'deliver_id':'0','refund_info':{'refund_status':'','item_id':'7336737643','item_sku_id':'0','refund_kind':'','refund_fee':'','refund_item_fee':'','can_refund':'1','refund_express_fee':''},'item_name':'农夫山泉东方树叶青柑普洱900ml单瓶','sku_id':'0','sub_order_id':656217033280013,'url':'https://weidian.com/item.html?itemID=7336737643','sku_title':'','price':'0.02','bar_code':'6921168598649','deliver_status_desc':'已完成','id':656217033280013,'can_deliver':0}],'order_id':'828105459755533','express_type':'0','status':'finish'},'shopId':1780485109,'type':'weidian.order.finished'}";
            string status = await WeiDianService.PushOrder(mjson);

            //string filePath = "~/up_file/";
            //string toFileFullPath = HttpContext.Current.Server.MapPath(filePath);
            //string toFileFullPath1 = HostingEnvironment.MapPath("/upload/weixin/");
            //var appModel = new SystemAppModel();
            //appModel.FCorpID = 21438;
            //appModel.FUserID = 15468;
            //appModel.FStockID = 16741;
            //appModel.FOwnerID = 0;
            //appModel.FParentID = 0;
            //appModel.FDtSplit = "1001";
            //appModel.FDbSplit = "2024";

            //shop_appid = SystemInfo.SetSystemAppID(appModel);
            ////ArrayList data = BusinessCommon.GetGoodClassList(shop_appid);

            //GoodsModel goodsModel = new GoodsModel();
            //goodsModel.FItemID = CommonFun.ConvertToBigInt(HttpContext.Current.Request["FItemID"]);
            //goodsModel.FNumber = "";
            //goodsModel.FName = "新增商品";
            //int mResult = 0;
            //string msg = "保存失败";
            //Hashtable ht_reust = MiniMngCommon.SetGoodsInfo(goodsModel, "uNZj+qel5cinjdXtIWvtmQ==", ref mResult, ref msg);
            //getJson();
            //GetTestData();
            //Hashtable data = MiniMngCommon.GetSmsData(shop_appid);

        }


        public void getBillData()
        {
            int bill_type = 1;
            Int64 bill_id = 772;
            ArrayList data = BusinessCommon.GetOrderList(shop_appid, "", 0, 15,
                "2021-01-01", "2022-12-01", 0, out int page_count);
        }

        public void getGoodsList()
        {            
            string name = "";
            int page_index = 0;
            int page_size = 15;
            ArrayList data = BusinessCommon.GetGoodsList(shop_appid, name,0, page_index, page_size, out int page_count);
            //Hashtable ht = BusinessCommon.GetGoodsDetail(shop_appid, 174788);
        }

        public async Task<bool> SetShoppingCart()
        {
            BusinessCommon businessCommon = new BusinessCommon();
            var result = businessCommon.SetShoppingCart(shop_appid, 174788,259);
            return true;
        }

        public void GetTestData()
        {

            int shop_id = 0;
            int page_index = 0;
            int page_size = 15;
            string star_date = "2022-01-01";
            string end_date = "2022-12-30";
            string bill_no = "";
            string name = "";
            int bill_type = 0;
            int bill_state = -1;
            string json = "{'FNumber':'','FName':'测试','FTelephone':'5555555555','FPassword':'123456','FType':1}";
            Hashtable row = (Hashtable)PluSoft.Utils.JSON.Decode(json);
            int mResult = 0;
            string msg = "保存失败";
            Hashtable ht_reust = MiniMngCommon.SetUserInfo(row, shop_appid, ref mResult, ref msg);
            string end = "";
        }

        public static void UploadImage(string uploadUrl, string imgPath, string fileparameter = "file")
        {
            HttpWebRequest request = WebRequest.Create(uploadUrl) as HttpWebRequest;
            request.AllowAutoRedirect = true;
            request.Method = "POST";

            string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
            request.ContentType = "multipart/form-data;charset=utf-8;boundary=" + boundary;
            byte[] itemBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "\r\n");
            byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");

            int pos = imgPath.LastIndexOf("/");
            string fileName = imgPath.Substring(pos + 1);

            //请求头部信息
            StringBuilder sbHeader = new StringBuilder(string.Format("Content-Disposition:form-data;name=\"" + fileparameter + "\";filename=\"{0}\"\r\nContent-Type:application/octet-stream\r\n\r\n", fileName));
            byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString());

            FileStream fs = new FileStream(imgPath, FileMode.Open, FileAccess.Read);
            byte[] bArr = new byte[fs.Length];
            fs.Read(bArr, 0, bArr.Length);
            fs.Close();

            Stream postStream = request.GetRequestStream();
            postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
            postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
            postStream.Write(bArr, 0, bArr.Length);
            postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
            postStream.Close();

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            Stream instream = response.GetResponseStream();
            StreamReader sr = new StreamReader(instream, Encoding.UTF8);
            string content = sr.ReadToEnd();
        }

        public void DeleteGoodsType()
        {
            Int64 FItemID = 16884;
            int type = 1;
            int mResult = 0;
            string msg = "删除失败";
            Hashtable ht_reust = MiniMngCommon.DeleteInfo(shop_appid, FItemID, type, ref mResult, ref msg);
        }

        public void getJson() {
            string shop_appid = "";
            MemberModel memberModel = new MemberModel();
            memberModel.FItemID = 0;
            memberModel.FNumber = "1001";
            memberModel.FName = "VIP";
            memberModel.FMembersClassID = 0;
            memberModel.FSex = 0;
            memberModel.FMemberRankID = 1;
            memberModel.FDiscount = 1;
            memberModel.FPhone = "13710387025";
            memberModel.FAddress = "";
            memberModel.FEmail = "";
            memberModel.FBirthday = "";
            memberModel.FRemark = "";
            memberModel.FSheAmount = 0;
            int mResult = 0;
            string msg = "保存失败";
            Hashtable ht_reust = MiniMngCommon.SetMemberInfo(memberModel, shop_appid, ref mResult, ref msg);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            getBillData();
        }
    }


}

